<%@page contentType="text/html;charset=utf-8" language="java"%>
<%@page import="com.ai.dmc.index.common.InitParam"%>
<%@page import="com.ai.dmc.index.web.util.SessionInfoUtil"%>
<%@page import="com.ai.dmc.index.common.bean.StaffSessBean"%>
<%@page import="com.ai.dmc.index.common.util.Base64"%>
<%
	StaffSessBean staffSessBean = SessionInfoUtil.getStaffSessBean(session);
	String curUserId = staffSessBean.getUserId();
	String curUserName = staffSessBean.getUserName();
	String curUserPwd = staffSessBean.getUserPassword();
	String curUserAreaId = staffSessBean.getAreaId();
	Boolean isAdmin = staffSessBean.isAdmin();

	String DEPLOY_TYPE_DEVELOP = InitParam.DEPLOY_TYPE_DEVELOP;
	String DEPLOY_TYPE_PRODUCT = InitParam.DEPLOY_TYPE_PRODUCT;
	String DEPLOY_TYPE = InitParam.DEPLOY_TYPE;
	String DATA_SOURCE = InitParam.DATA_SOURCE;
	String API_AGENT_FLAG = InitParam.API_AGENT_FLAG;
	String MAP_AGENT_URL = InitParam.MAP_AGENT_URL;
	String WEATHER_AGENT_URL = InitParam.WEATHER_AGENT_URL;
	String ADMIN_JOB_ID = InitParam.ADMIN_JOB_ID;
%>

<script src="../common/js/headv1.js"></script>
<script src="../common/js/jquery/jquery-1.11.3.min.js"></script>
<script src="../common/js/base.js"></script>

<script>
	// 参数定义
	var CONTENT_PATH               = '..';
	var curUserId                  = '<%=curUserId%>';
	var curUserName                = '<%=curUserName%>';
	var curUserAreaId              = '<%=curUserAreaId%>';
	var BASE64_KEY        		   = '<%=InitParam.BASE64_KEY%>';
	var CRYPTION_TYPE        	   = '<%=InitParam.CRYPTION_TYPE%>';
	var DEPLOY_TYPE_DEVELOP        = '<%=InitParam.DEPLOY_TYPE_DEVELOP%>';
	var DEPLOY_TYPE                = '<%=InitParam.DEPLOY_TYPE%>';
	var DEPLOY_PROVINCE            = '<%=InitParam.DEPLOY_PROVINCE%>';
	var DEPLOY_PROVINCE_ID         = '<%=InitParam.DEPLOY_PROVINCE_ID%>';
	var DEPLOY_ANALYSIS_PROVINCE_ID      = '<%=InitParam.DEPLOY_ANALYSIS_PROVINCE_ID%>';
	var DEPLOY_PROVINCE_CORE_LNG         = '<%=InitParam.DEPLOY_PROVINCE_CORE_LNG%>';
	var DEPLOY_PROVINCE_CORE_LAT         = '<%=InitParam.DEPLOY_PROVINCE_CORE_LAT%>';
	var DEPLOY_PROVINCE_CAPITAL_NAME = '<%=InitParam.DEPLOY_PROVINCE_CAPITAL_NAME%>';
	var DEPLOY_PROVINCE_NAME_SHORTHAND =  '<%=InitParam.DEPLOY_PROVINCE_NAME_SHORTHAND%>';
	var DEPLOY_PROVINCE_NAME       = '<%=InitParam.DEPLOY_PROVINCE_NAME%>';
	var DEPLOY_ID_CARD_PROVINCE_ID = '<%=InitParam.DEPLOY_ID_CARD_PROVINCE_ID%>';
	var DEPLOY_PROVINCE_NAME_SHORT = DEPLOY_PROVINCE_NAME.replace("省", "").replace("市", "").replace("自治区", "");
	var AREA_CITY_LENGTH           = '<%=InitParam.AREA_CITY_LENGTH%>';
	var AREA_COUNTY_LENGTH         = '<%=InitParam.AREA_COUNTY_LENGTH%>';
	var AREA_REGION_LENGTH         = '<%=InitParam.AREA_REGION_LENGTH%>';
	var AREA_SUB_REGION_LENGTH     = '<%=InitParam.AREA_SUB_REGION_LENGTH%>';
	var  API_AGENT_FLAG  = '<%=InitParam.API_AGENT_FLAG%>';
	var MAP_AGENT_URL = '<%=InitParam.MAP_AGENT_URL%>';
	var WEATHER_AGENT_URL = '<%=InitParam.WEATHER_AGENT_URL%>';
	var ADMIN_JOB_ID = '<%=InitParam.ADMIN_JOB_ID%>';
	var TOP_AREA_NAME = '<%=InitParam.TOP_AREA_NAME%>';
	var MAP_MINZOOM = '<%=InitParam.MAP_MINZOOM%>';
	var MAP_MAXZOOM = '<%=InitParam.MAP_MAXZOOM%>';
	// 参数定义
	var logoutUrl = CONTENT_PATH + '/common/jsp/logout.jsp';
	var errorUrl = CONTENT_PATH + '/common/jsp/error.html';
	var	pwdModifyUrl = CONTENT_PATH + '/zhly/pwd_modify.jsp';
	var	indexUrl = CONTENT_PATH + '/zhly/index.jsp';

	var lib_define = {
		'jquery' : {
			'css' : '',
			'js' : ''
		},
		'jquery-ui' : {
			'css' : [
				'/common/js/jquery-ui/themes/base/jquery-ui.css',
				'/common/js/jquery-ui/themes/base/jquery.ui.dialog.css'
			],
			'js' : '/common/js/jquery-ui/jquery-ui-1.9.2.custom.js'
		},
		'artDialog' : {
			'css' : '/common/js/artDialog/ui-dialog.css',
			'js' : [
				'/common/js/artDialog/dialog-min.js',
				'/common/js/artDialog/dialog-plus-min.js'
			]
		},
		'ztree' : {
			'css' : '/common/js/ztree/css/zTreeStyle/zTreeStyle.css',
			'js' : '/common/js/ztree/js/jquery.ztree.all-3.5.js'
		},
		'ztree_table' : {
			'css' : '/common/js/ztree/css/zTreeStyle/zTreeStyle_table.css',
			'js' : '/common/js/ztree/js/jquery.ztree.all-3.5.js'
		},
		'iconfont' : {
			'css' : '/common/iconfont/iconfont.css',
			'js' : ''
		},
		'base' : {
			'css' : '/common/css/base.css',
			'js' : ''
		},
		'page' : {
			'css' : '',
			'js' : '/common/js/page.js'
		},
		'md5' : {
			'css' : '',
			'js' : '/common/js/md5.js'
		},
		'echarts' : {
			'css' : '',
			'js' :  '/common/js/echarts.js'
		},
		'json' : {
			'css' : '',
			'js' :  '/common/js/json2.js'
		},
		'laydate' : {
			'css' : [
				'/common/js/laydate/need/laydate.css',
				'/common/js/laydate/skins/danlan/laydate.css'
			],
			'js' : '/common/js/laydate/laydate.dev.js'
		},
		'validate' : {
			'css' : '',
			'js' : '/common/js/validate.js'
		},
		'manage' : {
			'css' : '/manage/manage.css',
			'js' : '/manage/manage.js'
		},
		'baiduMapButton' : {
			'css' : '',
			'js' : [
				'/zhly/assets/js/BaiduMap/BMapButton.js'
			]
		},
		/* 'baiduMap' : {
			'css' : 'http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css',
			'js' : [
				'/common/js/baiduMap/bmap.js',
				'/common/js/baiduMap/bmap.config.js',
				'/common/js/baiduMap/AreaRestriction_min.js',
				'/common/js/baiduMap/BMapDrawingManager.js',
				'/common/js/baiduMap/BMapLib_GeoUtils.js',
				'/common/js/baiduMap/BMapButton.js'
			]
		}, */
		'zhly' : {
			'css' : [
			         '/zhly/assets/css/layout.css',
			         '/zhly/assets/css/public.css'
			         ],
			'js' : ''
		},
		'customselect' : {
			'css' : '',
			'js' : '/common/js/customselect.js'
		},
		'dfig' : {
			'css' : '/zhly/assets/css/custom_area.css',
			'js' : '/dfig/dfig.js'
		},
		'weather' : {
			'css' : '',
			'js' : '/common/js/weather.js'
		},
		'screen' : {
			'css' : [
				'/screen/assets/css/base.css',
				'/screen/assets/css/largescreen.css'
			],
			'js' : '/screen/index.js'
		}
	};
</script>

<%@include file="../../dev/tpl/common/common_js.tpl"%>
<%if(API_AGENT_FLAG.equals("true")){ %>
<script src="../common/js/baiduMap.js"></script>
<%}else{ %>
<script src="http://api.map.baidu.com/getscript?v=2.0&ak=sGZOkeDdDDh55kIiuYC2qUg1&services=&t=20150818132813"></script>
<%}%>
<script>
	// 判断是否是数组
	function _isArray(o) {
		return Object.prototype.toString.call(o) === '[object Array]';
	}

	// 让Array的indexOf支持IE8
	if (!Array.prototype.indexOf) {
		Array.prototype.indexOf = function(elt /*, from*/ ) {
			var len = this.length >>> 0;

			var from = Number(arguments[1]) || 0;
			from = (from < 0) ? Math.ceil(from) : Math.floor(from);
			if (from < 0)
				from += len;

			for (; from < len; from++) {
				if (from in this &&
					this[from] === elt)
					return from;
			}
			return -1;
		};
	}


	// 异步加载js和css
	function _requires(type, libs, callback) {
		// 时间戳，防止缓存
		/* var date = new Date();
		date = '?date=' + date; */
		var date = '?randomId=20160108095024';	//设置版本号，刷新负载均衡缓存

		libs = libs ? libs : [];

		// 默认加载通用框架
		libs.unshift('jquery', 'base', 'iconfont');

		//调整加载顺序，如有百度地图，则优先加载
		/* if(libs.indexOf('baiduMap') != -1){
			//head.load('http://api.map.baidu.com/getscript?v=2.0&ak=sGZOkeDdDDh55kIiuYC2qUg1&services=&t=20150818132813');
			//head.load('/dtkl/common/js/bmap.js');
		} */
		//head.load('http://api.map.baidu.com/getscript?v=2.0&ak=sGZOkeDdDDh55kIiuYC2qUg1&services=&t=20150818132813');
		//head.load('../common/js/baiduMap.js');

		// 加载css
		if('all' == type || 'css' == type){
			var css_arr = [];
			for (var i = 0; i < libs.length; i++) {
				var lib_name = libs[i];
				if (lib_name.indexOf('.css') != -1) {
					// 直接路径
					var lib_css = CONTENT_PATH + lib_name + date;
					css_arr.push(lib_css);
				} else {
					// 已经定义的lib
					var lib = lib_define[lib_name];
					if (null == lib) {
						continue;
					}
					var lib_css = lib.css;
					if (null == lib_css || lib_css.length < 1) {
						continue;
					}

					if (_isArray(lib_css)) {
						//多个
						for (var j = 0; j < lib_css.length; j++) {
							var css = lib_css[j];
							if (!/^http/.test(css)){
								css = CONTENT_PATH + css + date;
							}
							css_arr.push(css);
						}
						;
					} else {
						//单个
						if (!/^http/.test(lib_css)){
							lib_css = CONTENT_PATH + lib_css + date;
						}
						css_arr.push(lib_css);
					}
				}
			}
			for (var k = 0; k < css_arr.length; k++) {
				var c = css_arr[k];
				head.load(c);
			};
		}

		// 加载js
		if('all' == type || 'js' == type){
			var js_arr = [];
			for (var i = 0; i < libs.length; i++) {
				var lib_name = libs[i];
				if (lib_name.indexOf('.js') != -1) {
					// 直接路径
					var lib_js = CONTENT_PATH + lib_name + date;
					js_arr.push(lib_js);
				} else {
					// 已经定义的lib
					var lib = lib_define[lib_name];
					if (null == lib) {
						continue;
					}
					var lib_js = lib.js;
					if (null == lib_js || lib_js.length < 1) {
						continue;
					}

					if (_isArray(lib_js)) {
						//多个
						for (var j = 0; j < lib_js.length; j++) {
							var js = lib_js[j];
							if (!/^http/.test(js)){
								js = CONTENT_PATH + js + date;
							}
							js_arr.push(js);
						}
						;
					} else {
						//单个
						if (!/^http/.test(lib_js)){
							lib_js = CONTENT_PATH + lib_js + date;
						}
						js_arr.push(lib_js);
					}
				}
			}
			for (var k = 0; k < js_arr.length; k++) {
				var j = js_arr[k];
				head.load(j);
			};
		}
	}

	// 异步加载js和css
	function requires(libs, callback) {
		var type = 'all';
		_requires(type, libs, callback);
	}

	// 异步加载css
	function requires_css (libs, callback) {
		var type = 'css';
		_requires(type, libs, callback);
	}

	// 异步加载js
	function requires_js (libs, callback) {
		var type = 'js';
		_requires(type, libs, callback);
	}
</script>